package kr.hkit.androidcomplete02.ch16;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class DialogFragmentEx extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_dialogtest);
	}
	
	public void mOnClick(View v){
		DialogFragmentTest dlg = new DialogFragmentTest();
		// Manager, 구분자
		dlg.show(getFragmentManager(), "Dialog Fragement");
	}	

}

class DialogFragmentTest extends DialogFragment{	
	
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Log.d("DialogFragmentTest", "onCreateDialog()");
		
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle("알립니다")
		.setMessage("DialogFragment를 열었습니다.")
		.setPositiveButton("확인", new OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(getActivity(), "확인 버튼 누름", Toast.LENGTH_SHORT).show();
			}
		})
		.setNegativeButton("닫기", null)
		.create();
		
		return builder.create();
		
		/*return new AlertDialog.Builder(getActivity())
		.setTitle("알립니다")
		.setMessage("DialogFragment를 열었습니다.")
		.setPositiveButton("확인", new OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(getActivity(), "확인 버튼 누름", Toast.LENGTH_SHORT).show();
			}
		})
		.setNegativeButton("닫기", null)
		.create();*/
	}
}
